package com.parenting.controller;


import com.parenting.model.IMPage;
import com.parenting.request.*;
import com.parenting.request.platform.AddPlatformShopRequest;
import com.parenting.request.platform.ExamineApprove;
import com.parenting.request.platform.ShopSearchConditionRequest;
import com.parenting.response.platform.ClaimNotice;
import com.parenting.response.platform.PageShopListResponse;
import com.parenting.response.platform.StoreDetailsResponse;
import com.parenting.service.ParentingShopService;
import com.parenting.util.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 店铺主表 前端控制器
 * </p>
 *
 * @author 烟台业达-王世玺
 * @since 2021-08-18
 */
@RestController
@Api(tags = "店铺管理接口", description = "店铺（曾、改、查、店铺未认领列表、店铺认领）")
@RequestMapping("/shop")
@Slf4j
public class ParentingShopController {

    @Autowired
    private ParentingShopService parentingShopService;

    /****
     *  新增店铺
     * @param shop  店铺实体类
     */
    @ApiOperation("新增店铺")
    @PostMapping
    public Result savePlatformShop(@RequestBody AddPlatformShopRequest shop){
       parentingShopService.savePlatformShop(shop);
       return  Result.success();
   }


    @ApiOperation("校验店铺是否存在")
    @PostMapping("chek")
    public Result chekShop(@RequestBody  ChekShopRequest shop){

        return Result.ok(parentingShopService.chekShop(shop));
    }


    @ApiOperation("店铺列表")
    @PostMapping("page")
    public  Result<IMPage<PageShopListResponse>> getPageShopList(@RequestBody ShopSearchConditionRequest request){
        IMPage<PageShopListResponse> pageShopListResponseIMPage = parentingShopService.pageShopList(request);
        return Result.buildSuccess(pageShopListResponseIMPage);
    }


    @ApiOperation("店铺详情")
    @PostMapping("shop/{id}")
    public Result<StoreDetailsResponse> getShopById(@PathVariable("id") String id){
        StoreDetailsResponse shopById = parentingShopService.getShopById(id);
        return  Result.buildSuccess(shopById);
    }



    @ApiOperation("店铺删除")
    @DeleteMapping("remove/{id}")
    public Result deleteShopById(@PathVariable("id") String id){

      parentingShopService.deleteShopById(id);
        return  Result.buildSuccess();
    }


    @ApiOperation("店铺认领通知列表")
    @ApiImplicitParam(name = "state", value = "状态 ：0查询所有 ，3待审批、4已审批、5已拒绝", required = true)
    @GetMapping("claim/notice/list/{state}")
    public Result<List<ClaimNotice>> getClaimNoticeList(@PathVariable("state") Integer state){
        log.info("=========== {} " ,state);
        List<ClaimNotice> claimNoticeList = parentingShopService.getClaimNoticeList(state);
        return Result.buildSuccess(claimNoticeList);
    }

    @ApiOperation("店铺认领审批")
    @PostMapping("examine/approve")
    public Result updateExamineShop(@RequestBody ExamineApprove examineApprove){
        parentingShopService.updateExamineShop(examineApprove);
        return Result.buildSuccess();
    }

}

